package leetcode.editor.cn;

public class _53_MaximumSubarray {
    public static void main(String[] args) {
        Solution solution = new _53_MaximumSubarray().new Solution();
    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public int maxSubArray(int[] nums) {
            int res = nums[0];
            int sum = res;
            for (int i = 1; i < nums.length; i++) {
                if (sum < 0) {
                    sum = 0;
                }
                sum += nums[i];
                res = Math.max(sum, res);
            }
            return res;
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}